package com.xt.myapplication;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;


public class AdapterCurrentTaskLogInfo extends BaseAdapter {

    private Context context;
    private List<String> listTaskInfo;

    public AdapterCurrentTaskLogInfo(Context context) {
        this.context = context;
        listTaskInfo = new ArrayList<>();
    }

    public void addTaskInfo(String info) {
        listTaskInfo.add(info);
    }

    public void clearAll(){
        listTaskInfo = new ArrayList<>();
    }


    @Override
    public int getCount() {
        return listTaskInfo.size();
    }

    @Override
    public String getItem(int position) {
        if (position > listTaskInfo.size())
            return null;
        return listTaskInfo.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView != null) {
            holder = (ViewHolder) convertView.getTag();
        } else {
            convertView = View.inflate(context, R.layout.adapter_current_task_log_info, null);
            holder = new ViewHolder();
            convertView.setTag(holder);
            holder.textViewCurrentLogInfo = convertView.findViewById(R.id.textViewCurrentLogInfo);
        }

        final String deviceModel = getItem(position);
        if (deviceModel != null) {
            holder.textViewCurrentLogInfo.setText(String.format("%d-%s", position, deviceModel));
        }


        return convertView;
    }

    class ViewHolder {
        TextView textViewCurrentLogInfo;
    }
}
